﻿using System;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using advadev.CanOpen;


namespace advadev.CanOpen.UnitTests
{

    /// <summary>
    /// Represents the process data object write transfer unit tests
    /// </summary>
    [TestClass]
    public class ProcessDataObjectWriteTransferTest : ICanOpenObjectDictionaryContainer
    {

        #region constructor tests
        /// <summary>
        /// Constructor test
        /// </summary>
        [TestMethod]
        public void ConstructorTest()
        {
            // initialization
            byte nodeId = 103;
            List<ICanOpenValueObject> canOpenValueObjects = new List<ICanOpenValueObject>();
            ProcessDataObjectWriteTransfer testObject = null;

            // can open value objects null parameter
            try
            {
                testObject = new ProcessDataObjectWriteTransfer(null, nodeId, 0x180);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
            }
            catch
            {
                Assert.Fail();
            }

            // node id out of range parameter
            try
            {
                testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, 0, 0x180);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            catch
            {
                Assert.Fail();
            }
            try
            {
                testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, 128, 0x180);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
        #endregion constructor tests


        #region producer side tests
        /// <summary>
        /// Producer side test
        /// </summary>
        [TestMethod]
        public void ProducerSideTest()
        {
            // initialization
            byte nodeId = 103;
            UInt16 cobId = 0x180;
            CanOpenUnsigned8 unsigned8_1 = new CanOpenUnsigned8(0x0008, 0x01, true, true);
            CanOpenUnsigned8 unsigned8_2 = new CanOpenUnsigned8(0x0008, 0x02, true, true);
            CanOpenUnsigned8 unsigned8_3 = new CanOpenUnsigned8(0x0008, 0x03, true, true);
            CanOpenUnsigned16 unsigned16_1 = new CanOpenUnsigned16(0x0016, 0x01, true, true);
            CanOpenUnsigned16 unsigned16_2 = new CanOpenUnsigned16(0x0016, 0x02, true, true);
            CanOpenUnsigned56 unsigned56_1 = new CanOpenUnsigned56(0x0056, 0x01, true, true);
            CanOpenUnsigned56 unsigned56_2 = new CanOpenUnsigned56(0x0056, 0x02, true, true);
            List<ICanOpenValueObject> canOpenValueObjects = new List<ICanOpenValueObject>();
            ProcessDataObjectWriteTransfer testObject = null;

            // test with single 8 bit object
            unsigned8_1.Value = 100;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned8_1);
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x64, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)1, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with single 16 bit object
            unsigned16_1.Value = 10000;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned16_1);
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x10, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0x27, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)2, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with three 8 bit objects
            unsigned8_1.Value = 100;
            unsigned8_2.Value = 200;
            unsigned8_3.Value = 255;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned8_1);
            canOpenValueObjects.Add(unsigned8_2);
            canOpenValueObjects.Add(unsigned8_3);
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x64, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0xC8, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0xFF, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)3, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with two 16 bit objects
            unsigned16_1.Value = 10000;
            unsigned16_2.Value = 65535;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned16_1);
            canOpenValueObjects.Add(unsigned16_2);
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x10, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0x27, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0xFF, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0xFF, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)4, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with empty list
            canOpenValueObjects.Clear();
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)0, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with two 56 bit objects
            unsigned56_1.Value = 10000000000000000;
            unsigned56_2.Value = 0xFFFFFFFFFFFFFF;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned56_1);
            canOpenValueObjects.Add(unsigned56_2);
            testObject = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId);
            testObject.Start();
            Assert.AreEqual(false, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(1, testObject.PendingSendMessages.Count);
            Assert.AreEqual(0x1E7, testObject.PendingSendMessages[0].CanId);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte0);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte1);
            Assert.AreEqual(0xC1, testObject.PendingSendMessages[0].Byte2);
            Assert.AreEqual(0x6F, testObject.PendingSendMessages[0].Byte3);
            Assert.AreEqual(0xF2, testObject.PendingSendMessages[0].Byte4);
            Assert.AreEqual(0x86, testObject.PendingSendMessages[0].Byte5);
            Assert.AreEqual(0x23, testObject.PendingSendMessages[0].Byte6);
            Assert.AreEqual(0x00, testObject.PendingSendMessages[0].Byte7);
            Assert.AreEqual((uint)7, testObject.PendingSendMessages[0].Length);
            testObject.ContinueAfterSendingMessages();
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);
        }
        #endregion producer side tests


        #region is process data object write transfer request tests
        /// <summary>
        /// Is process data object write transfer request test
        /// </summary>
        [TestMethod]
        public void IsProcessDataObjectWriteTransferRequestTest()
        {
            // initialization
            bool isProcessDataObjectWriteTransferRequest = false;
            uint pdoIndex = 0;
            List<ICanOpenValueObject> canOpenValueObjects = new List<ICanOpenValueObject>();
            ProcessDataObjectWriteTransfer testObject = null;

            // test with valid received can open message
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(new CanOpenMessage(0x1E7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(true, isProcessDataObjectWriteTransferRequest);
            Assert.IsNotNull(testObject);

            // test with not valid received can open message
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(new CanOpenMessage(0x180, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(false, isProcessDataObjectWriteTransferRequest);
            Assert.IsNull(testObject);

            // test with can open object dictionary is null
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(new CanOpenMessage(0x1E7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), null, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(false, isProcessDataObjectWriteTransferRequest);
            Assert.IsNull(testObject);

            // test with received can open message is null
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(null, this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(false, isProcessDataObjectWriteTransferRequest);
            Assert.IsNull(testObject);

            // test with COB-ID parameter list is null
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(new CanOpenMessage(0x1E7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), this, out testObject, out pdoIndex, null);
            Assert.AreEqual(false, isProcessDataObjectWriteTransferRequest);
            Assert.IsNull(testObject);
        }
        #endregion is process data object write transfer request tests


        #region consumer side tests
        /// <summary>
        /// Consumer side test
        /// </summary>
        [TestMethod]
        public void ComsumerSideTest()
        {
            // initialization
            bool isProcessDataObjectWriteTransferRequest = false;
            byte nodeId = 103;
            uint pdoIndex = 0;
            UInt16 cobId1 = 0x180;
            UInt16 cobId2 = 0x280;
            CanOpenUnsigned8 unsigned8_1 = new CanOpenUnsigned8(0x0008, 0x01, true, true);
            CanOpenUnsigned8 unsigned8_2 = new CanOpenUnsigned8(0x0008, 0x02, true, true);
            CanOpenUnsigned8 unsigned8_3 = new CanOpenUnsigned8(0x0008, 0x03, true, true);
            CanOpenUnsigned16 unsigned16_1 = new CanOpenUnsigned16(0x0016, 0x01, true, true);
            CanOpenUnsigned16 unsigned16_2 = new CanOpenUnsigned16(0x0016, 0x02, true, true);
            CanOpenUnsigned16 unsigned16_3 = new CanOpenUnsigned16(0x0016, 0x03, true, true);
            CanOpenUnsigned56 unsigned56_1 = new CanOpenUnsigned56(0x0056, 0x01, true, true);
            CanOpenUnsigned56 unsigned56_2 = new CanOpenUnsigned56(0x0056, 0x02, true, true);
            List<ICanOpenValueObject> canOpenValueObjects = new List<ICanOpenValueObject>();
            ProcessDataObjectWriteTransfer testObject = null;
            ProcessDataObjectWriteTransfer producerTransfer = null;

            // test with single 8 bit object
            unsigned8_1.Value = 100;
            _canOpenUnsigned8_1.Value = 0;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned8_1);
            producerTransfer = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId1);
            producerTransfer.Start();
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(producerTransfer.PendingSendMessages[0], this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(true, isProcessDataObjectWriteTransferRequest);
            Assert.IsNotNull(testObject);
            testObject.Start();
            Assert.AreEqual(unsigned8_1.Value, _canOpenUnsigned8_1.Value);
            Assert.AreEqual((uint)0, pdoIndex);
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with single 16 bit object
            unsigned16_1.Value = 10000;
            _canOpenUnsigned16_1.Value = 0;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned16_1);
            producerTransfer = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId2);
            producerTransfer.Start();
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(producerTransfer.PendingSendMessages[0], this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(true, isProcessDataObjectWriteTransferRequest);
            Assert.IsNotNull(testObject);
            testObject.Start();
            Assert.AreEqual(unsigned16_1.Value, _canOpenUnsigned16_1.Value);
            Assert.AreEqual((uint)1, pdoIndex);
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with three 8 bit object
            unsigned8_1.Value = 100;
            unsigned8_2.Value = 200;
            unsigned8_3.Value = 255;
            _canOpenUnsigned8_1.Value = 0;
            _canOpenUnsigned8_2.Value = 0;
            _canOpenUnsigned8_3.Value = 0;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned8_1);
            canOpenValueObjects.Add(unsigned8_2);
            canOpenValueObjects.Add(unsigned8_3);
            producerTransfer = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId1);
            producerTransfer.Start();
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(producerTransfer.PendingSendMessages[0], this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(true, isProcessDataObjectWriteTransferRequest);
            Assert.IsNotNull(testObject);
            testObject.Start();
            Assert.AreEqual(unsigned8_1.Value, _canOpenUnsigned8_1.Value);
            Assert.AreEqual(unsigned8_2.Value, _canOpenUnsigned8_2.Value);
            Assert.AreEqual(unsigned8_3.Value, _canOpenUnsigned8_3.Value);
            Assert.AreEqual((uint)0, pdoIndex);
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with two 16 bit object
            unsigned16_1.Value = 10000;
            unsigned16_2.Value = 65535;
            _canOpenUnsigned16_1.Value = 0;
            _canOpenUnsigned16_2.Value = 0;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned16_1);
            canOpenValueObjects.Add(unsigned16_2);
            producerTransfer = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId2);
            producerTransfer.Start();
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(producerTransfer.PendingSendMessages[0], this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(true, isProcessDataObjectWriteTransferRequest);
            Assert.IsNotNull(testObject);
            testObject.Start();
            Assert.AreEqual(unsigned16_1.Value, _canOpenUnsigned16_1.Value);
            Assert.AreEqual(unsigned16_2.Value, _canOpenUnsigned16_2.Value);
            Assert.AreEqual((uint)1, pdoIndex);
            Assert.AreEqual(true, testObject.TransferComplete);
            Assert.IsNull(testObject.AbortCode);
            Assert.IsNotNull(testObject.PendingSendMessages);
            Assert.AreEqual(0, testObject.PendingSendMessages.Count);

            // test with not active PDO
            _receiveCobId1.Value += 0x80000000;
            unsigned8_1.Value = 100;
            _canOpenUnsigned8_1.Value = 0;
            canOpenValueObjects.Clear();
            canOpenValueObjects.Add(unsigned8_1);
            producerTransfer = new ProcessDataObjectWriteTransfer(canOpenValueObjects, nodeId, cobId1);
            producerTransfer.Start();
            isProcessDataObjectWriteTransferRequest = ProcessDataObjectWriteTransfer.IsProcessDataObjectWriteTransfer(producerTransfer.PendingSendMessages[0], this, out testObject, out pdoIndex, new List<CanOpenUnsigned> { _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4 });
            Assert.AreEqual(false, isProcessDataObjectWriteTransferRequest);
            Assert.IsNull(testObject);
            Assert.AreEqual((ulong)0, _canOpenUnsigned8_1.Value);
            Assert.AreEqual((uint)0, pdoIndex);
            _receiveCobId1.Value -= 0x80000000;
        }
        #endregion consumer side tests


        #region ICanOpenObjectDictionaryContainer
        /// <summary>for internal use</summary>
        private CanOpenUnsigned8 _canOpenUnsigned8_1 = new CanOpenUnsigned8(0x0008, 0x01, true, true);
        /// <summary>for internal use</summary>
        private CanOpenUnsigned8 _canOpenUnsigned8_2 = new CanOpenUnsigned8(0x0008, 0x02, true, true);
        /// <summary>for internal use</summary>
        private CanOpenUnsigned8 _canOpenUnsigned8_3 = new CanOpenUnsigned8(0x0008, 0x03, true, true);
        /// <summary>for internal use</summary>
        private CanOpenUnsigned16 _canOpenUnsigned16_1 = new CanOpenUnsigned16(0x0016, 0x01, true, true);
        /// <summary>for internal use</summary>
        private CanOpenUnsigned16 _canOpenUnsigned16_2 = new CanOpenUnsigned16(0x0016, 0x02, true, true);
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveCobId1 = new CanOpenUnsigned32(0x1400, 0x01, true, true) { Value = 0x180 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveCobId2 = new CanOpenUnsigned32(0x1401, 0x01, true, true) { Value = 0x280 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveCobId3 = new CanOpenUnsigned32(0x1402, 0x01, true, true) { Value = 0x380 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveCobId4 = new CanOpenUnsigned32(0x1403, 0x01, true, true) { Value = 0x480 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMappingSize1 = new CanOpenUnsigned32(0x1600, 0x00, true, true) { Value = 3 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMappingSize2 = new CanOpenUnsigned32(0x1601, 0x00, true, true) { Value = 3 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMapping1Object1 = new CanOpenUnsigned32(0x1600, 0x01, true, true) { Value = 0x08000108 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMapping1Object2 = new CanOpenUnsigned32(0x1600, 0x02, true, true) { Value = 0x08000208 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMapping1Object3 = new CanOpenUnsigned32(0x1600, 0x03, true, true) { Value = 0x08000308 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMapping2Object1 = new CanOpenUnsigned32(0x1601, 0x01, true, true) { Value = 0x16000110 };
        /// <summary>for internal use</summary>
        private CanOpenUnsigned32 _receiveMapping2Object2 = new CanOpenUnsigned32(0x1601, 0x02, true, true) { Value = 0x16000210 };
        /// <summary>for internal use</summary>
        private List<ICanOpenValueObject> _objects;

        /// <summary>
        /// Gets the node id of the can open object dictionary container
        /// </summary>
        byte ICanOpenObjectDictionaryContainer.NodeId
        {
            get
            {
                return 103;
            }
        }

        /// <summary>
        /// Gets the can open object with the given index as can open data field
        /// object
        /// </summary>
        /// <param name="index">
        /// Index of the can open object to get
        /// </param>
        /// <returns>
        /// The can open object with the given index as data field object or
        /// null
        /// </returns>
        ICanOpenDataFieldObject ICanOpenObjectDictionaryContainer.GetCanOpenObject(UInt16 index)
        {
            return null;
        }

        /// <summary>
        /// Gets the can open object with the given index and sub index as can
        /// open value object
        /// </summary>
        /// <param name="index">
        /// Index of the can open object to get
        /// </param>
        /// <param name="subIndex">
        /// Sub index of the can open object to get
        /// </param>
        /// <returns>
        /// The can open object with the given index and sub index as value
        /// object or null
        /// </returns>
        ICanOpenValueObject ICanOpenObjectDictionaryContainer.GetCanOpenObject(UInt16 index, byte subIndex)
        {
            if (_objects == null)
            {
                _objects = new List<ICanOpenValueObject>() { _canOpenUnsigned8_1, _canOpenUnsigned8_2, _canOpenUnsigned8_3, _canOpenUnsigned16_1, _canOpenUnsigned16_2, _receiveCobId1, _receiveCobId2, _receiveCobId3, _receiveCobId4, _receiveMappingSize1, _receiveMappingSize2, _receiveMapping1Object1, _receiveMapping1Object2, _receiveMapping1Object3, _receiveMapping2Object1, _receiveMapping2Object2 };
            }
            foreach (ICanOpenValueObject canOpenObject in _objects)
            {
                if (canOpenObject.Index == index && canOpenObject.SubIndex == subIndex)
                {
                    return canOpenObject;
                }
            }
            return null;
        }
        #endregion ICanOpenObjectDictionaryContainer

    }

}
